package com.example.service.impl;

import com.example.dao.CouponMapper;
import com.example.dao.CouponTemplateMapper;
import com.example.model.Coupon;
import com.example.model.CouponTemplate;
import com.example.service.TemplateService;
import com.example.service.manage.ConvertVoToRequest;
import com.example.vo.TemplateRequest;
import com.example.vo.TemplateVO;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TemplateServiceImpl implements TemplateService {
    private final ConvertVoToRequest convertVoToRequest;

    private final CouponMapper couponMapper;
    private final CouponTemplateMapper couponTemplateMapper;
    public TemplateServiceImpl(ConvertVoToRequest convertVoToRequest, final CouponMapper couponMapper, final CouponTemplateMapper couponTemplateMapper) {
        this.convertVoToRequest = convertVoToRequest;
        this.couponMapper = couponMapper;
        this.couponTemplateMapper = couponTemplateMapper;
    }

    @Override
    public Map<String, String> queryPageList(TemplateVO templateVO) {
        final TemplateRequest request = convertVoToRequest.templateVoToTemplateRequest(templateVO);
//        TODO 增加nacos 依赖
//        TODO 增加fegin依赖
//        TODO 增加fegin调用公共方法
//        TODO 使用fegin调用template模板服务
//        TODO 对template模板服务返回值进行处理
//        TODO 构造返回值给前端
        return null;
    }

    @Override
    public Map<String, String> queryPageList() {
        // 直接查询数据库
        // 先查模板表，再查优惠劵模板表
        final List<Coupon> couponList = couponMapper.selectByExample(new Coupon());
        final List<CouponTemplate> couponTemplates = couponTemplateMapper.selectByExample(new CouponTemplate());

        final HashMap<Integer, Coupon> connectMap = new HashMap<>(16);
        //遍历查询出的数据,填充入联表Map
        couponList.forEach(coupon -> connectMap.put(coupon.getTemplateId(), coupon));
        //数据填充+构造为List<VO>对象
        final ArrayList<TemplateVO> templateVOList = new ArrayList<>(16);
        couponTemplates.forEach(couponTemplate ->{
            final Coupon coupon = connectMap.get(couponTemplate.getId());
            //    根据coupon和template对象构造VO

            final TemplateVO templateVO = new TemplateVO();
            templateVO.setId();
            templateVO.setName();
            templateVO.setLogo();
            templateVO.setDesc();
            templateVO.setCategory();
            templateVO.setProductLine();
            templateVO.setKey();
            templateVO.setTarget();
            templateVO.setPeriod();
            templateVO.setGap();
            templateVO.setDeadline();
            templateVO.setQuota();
            templateVO.setBase();
            templateVO.setLimitation();
            templateVO.setProvince();
            templateVO.setCity();
            templateVO.setGoodsType();
            templateVO.setWeight();

            templateVOList.add(templateVO);
            });
        //Vo list转Map
        return null;
    }
}
